package com.newcoder.community.util;

import com.newcoder.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * 持有用户的信息，用于代替session对象，显示线程隔离
 *
 * ClassName:HostHolder
 * Package:com.newcoder.community.util
 *
 * @author: pf
 * @date: 2021/11/30-13:17
 */

@Component
public class HostHolder {

    private ThreadLocal<User> users = new ThreadLocal<>();

    public void setUser(User user) {
        users.set(user);
    }

    public User getUser() {
        return users.get();
    }

    // 清理
    public void clear() {
        users.remove();
    }


}
